
%clear


nExamples_per_class = [20 20 20]  %[20 10 30];
nExamples = sum(nExamples_per_class);
nLabels = length(nExamples_per_class);   %  3 classes


examples = randn(nExamples, 4);


% 1st feature:  All means are the same

% 2nd feature: 3rd class has different mean
idx = sum(nExamples_per_class(1:2)) + 1;
examples(idx:end,2) = examples(idx:end,2) + 1; 

% 3rd feature:  2nd and 3rd class have mean different from 1st
idx = sum(nExamples_per_class(1)) + 1;
examples(idx:end,3) = examples(idx:end,3) + 1;

% Fourth feature:  2nd and 3rd class have different means
idx = sum(nExamples_per_class(1)) + 1;
examples(idx:end,4) = examples(idx:end,4) + 1;
idx = sum(nExamples_per_class(1:2)) + 1;
examples(idx:end,4) = examples(idx:end,4) + 2;

labels = zeros(nExamples,1);
idx = 1;
for l = 1:nLabels
  labels(idx:(sum(nExamples_per_class(1:l)))) = l;
  idx = sum(nExamples_per_class(1:l)) + 1;
end
  

examples = examples';   % the examples must be in the form [num_features x num_examples]  !!!



tic
[sortedFeatures_new, pvalues_new] = rank_features_using_an_ANOVA(examples,labels);
new_time = toc;


for i = 1:size(examples, 1)
    anova1_pvals(i) = anova1(examples(i, :), labels, 'off');
end



diff_in_pvals = anova1_pvals - pvalues_new

if sum(abs(diff_in_pvals)) < .000000000001
    'Everything seems ok'
else
    'Problems, new code is not replicating previous results!!!'
end

















